package com.conan.spring5.dao;

import com.conan.spring5.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @version 加油！！！
 * @Description
 * @Author 谷藤新一GYC
 * @Date 2022/10/22 - 15:59
 */
@Repository
public class UserDAOImpl implements UserDAO{

    @Autowired
    private JdbcTemplate jdbcTemplate;

    //多钱
    @Override
    public void addMoney(Integer money, User user) {
        jdbcTemplate.update("update t_account set money=money + ? where id=?",money,user.getId());
    }
    //少钱
    @Override
    public void reduceMoney(Integer money, User user) {
        jdbcTemplate.update("update t_account set money=money - ? where id=?",money,user.getId());
    }

    @Override
    public User getUserById(Integer id) {
        return jdbcTemplate.queryForObject("select * from t_account where id = ?",new BeanPropertyRowMapper<User>(User.class),id);
    }
}
   